#!/bin/bash
# **********************************************************
# * Author : liangliangSu
# * Email : sll917@hotmail.com
# * Create time : 2023-08-23 11:49
# * Filename : 21modify_string.sh
# **********************************************************
# 1，封装函数，实现批量修改文件内容：
read -p '请输入修改前旧的字符串: ' old_str
read -p '请输入修改后新的字符串: ' new_str
# read -p '请输入修改的工序是 BDP、CAL、S3D: ' work_station
read -p '请输入需要查询的字符串: ' check_str
 
# 定义函数 
function Modify()
{
	M=$(find . -name "*.csv")
	if [ $? == "0" ];then
		for files in $M
		do
			sed -i s/${old_str}/${new_str}/g $files
		done
	else
		echo "未找到匹配的文件。。。"
		sleep 3
	fi
}
Modify
grep -r "^?${check_str}" `find . -name "*.csv"` | awk -F "/" '{print $3,$4,$5,$6}'

# 定义函数 CAL
# function CAL()
# {
# 	M=$(find . -name "*.csv")
# 	if [ $? == "0" ];then
# 		for files in $M
# 		do
# 			sed -i s/${old_str}/${new_str}/g $files
# 		done
# 	else
# 		echo "未找到匹配的文件。。。"
# 		sleep 3
# 	fi
# 	N=$(find . -name "*.csv")
# 	grep -r "^?${check_str}" $N
# 	# grep -r "^?${check_str}" TestFile/*/BDP/*.csv
# }
#  
# # 定义函数 S3D
# function S3D()
# {
# 	M=$(find . -name "*.csv")
# 	if [ $? == "0" ];then
# 		for files in $M
# 		do
# 			sed -i s/${old_str}/${new_str}/g $files
# 		done
# 	else
# 		echo "未找到匹配的文件。。。"
# 		sleep 3
# 	fi
# 	N=$(find . -name "*.csv")
# 	grep -r "^?${check_str}" $N
# 	# grep -r "^?${check_str}" TestFile/*/BDP/*.csv
# }
#  
# # 判断修改的类型文件
# if [ ${work_station} == "BDP" ];then
# 	BDP
# elif [ ${work_station} == "CAL" ];then
# 	CAL
# elif [ ${work_station} == "S3D" ];then
# 	S3D
# else
# 	echo "输入错误，请重新输入："
# fi
